<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- <div v-for="item in books" :key="item.id">
        <div>{{ item.name }} - {{ item.price }}</div>

        @my-click="changePrice"
        @my-click="changePrice($event)"
      </div> -->

      <book
        v-for="item in books"
        :key="item.id"
        :name="item.name"
        :price="item.price"
        :aaa="100"
        @my-click="changePrice(item.id, $event)"
      ></book>
    </div>

    <script src="./js/vue.js"></script>
    <script>
      Vue.config.productionTip = false;

      Vue.component("book", {
        props: ["name", "price", "aaa"],
        template: `
          <div>
            <div>
              {{ name }} - {{ price }} - <button @click="callFather">涨价100快</button>
            </div>
          </div>
        `,
        methods: {
          callFather() {
            this.$emit("my-click", 100);
          },
        },
      });

      new Vue({
        el: "#app",
        data: {
          books: [
            {
              id: "001",
              name: "西游记",
              price: 100,
            },
            {
              id: "002",
              name: "金*梅",
              price: 1000,
            },
          ],
        },
        methods: {
          changePrice(event, priceA) {
            console.log("event: ", event); // 001 002
            console.log("price: ", price);
            // this.books.xxx.i;
            // this.books[event]

            this.books.find((book) => book.id === event).price += priceA;
          },
        },
      });
    </script>
  </body>
</html>
